<?php

class Tag extends CI_Model
{

    var $id = '';
    var $name = '';

    function __construct()
    {
        parent::__construct();
    }

    function get_last_ten_entries()
    {
        $query = $this->db->get('Tag', 10);
        return $query->result();
    }

    function save()
    {
        $this->name = $this->input->get('name');
        $this->db->insert('Tag', $this);
    }

    function update()
    {
        $this->name = $this->input->get('name');
        $this->db->update('Tag', $this, array('id' => $this->input->post('id')));
    }

    function get_tags($pid){
        $query = $this->db->query("select name from tag where id in (select tag_id from tagging where product_id = $pid)");
        return $query->result();
    }

}